package com.kfm.base.io.b;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Demo04 {
    public static void main(String[] args) {
        try(FileInputStream fis = new FileInputStream("d:/io/buffered-input.txt");
            BufferedInputStream bis = new BufferedInputStream(fis, 15);){
            System.out.println(bis.markSupported());
            // 第一次读取会先读取到缓冲区, 从缓冲区读取数据
            byte[] bytes = new byte[10];
            int size = bis.read(bytes);
            System.out.println(new String(bytes));

            // 标记
            bis.mark(1);

            size = bis.read(bytes);
            System.out.println(new String(bytes));

            // 重置
            bis.reset();
            int read = bis.read();
            System.out.println((char)read);

            System.out.println(bis.available());
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
